home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
004
/
pi.arc
/
PI.BAS
Wrap
BASIC Source File
|
1985-09-27
|
2KB
|
120 lines
10 PRINT "MULTIPLE PRECISION COMPUTATION OF PI TO Q DECIMAL PLACES"
20 PRINT
30 INPUT "Enter number of decimal places to be calculated ";Q
40 REM
50 REM P WILL CONTAIN PI. T IS THE AUXILLARY ARRAY.
60 REM
70 DIM P(Q), T(Q)
80 REM
90 REM * * * * * * * * * * * * * * * * * * * *
100 REM MAIN PROGRAM - COMPUTATION OF PI
110 REM * * * * * * * * * * * * * * * * * * *
120 REM
130 LET S=2
140 GOSUB 270
150 LET S=3
160 GOSUB 270
170 GOSUB 1090
180 FOR M=0 TO Q
190 PRINT P(M);
200 NEXT M
210 END
220 REM
230 REM * * * * * * * * * * * *
240 REM END OF MAIN PROGRAM
250 REM * * * * * * * * * * * *
260 REM
270 REM COMPUTE ARC TANGENT
280 REM
290 LET T(0)=1
300 LET L=S
310 GOSUB 850
320 GOSUB 490
330 N=1
340 GOSUB 730
350 L=S*S
360 GOSUB 850
370 N=N+2
380 L=N
390 GOSUB 850
400 IF ((N-1)\2) MOD 2=0 GOTO 430
410 GOSUB 610
420 GOTO 440
430 GOSUB 490
440 GOSUB 970
450 IF Z>0 GOTO 340
460 RETURN
470 END
480 REM
490 REM SUBROUTINE TO ADD ARRAYS
500 REM
510 FOR J=Q TO 0 STEP -1
520 IF T(J)+P(J)>9 GOTO 550
530 P(J)=T(J)+P(J)
540 GOTO 570
550 P(J)=T(J)+P(J)-10
560 P(J-1)=P(J-1)+1
570 NEXT J
580 RETURN
590 END
600 REM
610 REM SUBROUTINE TO SUBTRACT ARRAYS
620 REM
630 FOR J=Q TO 0 STEP -1
640 IF P(J)<T(J) GOTO 670
650 P(J)=P(J)-T(J)
660 GOTO 690
670 P(J)=P(J)-T(J)+10
680 P(J-1)=P(J-1)-1
690 NEXT J
700 RETURN
710 END
720 REM
730 REM SUBROUTINE TO MULTIPLY ARRAY T BY N
740 REM
750 C=0
760 D=0
770 FOR I=Q TO 0 STEP -1
780 D=(T(I)*N+C) MOD 10
790 C=(T(I)*N+C)\10
800 LET T(I)=D
810 NEXT I
820 RETURN
830 END
840 REM
850 REM SUBROUTINE TO DIVIDE ARRAY T BY L
860 REM
870 C=O
880 D=0
890 FOR K=0 TO Q
900 C=(10*D+T(K))\L
910 D=(10*D+T(K)) MOD L
920 T(K)=C
930 NEXT K
940 RETURN
950 END
960 REM
970 REM SUBROUTINE TO CHECK IF ARRAY T IS 0
980 REM
990 Z=0
1000 K=0
1010 IF T(K)=0 GOTO 1040
1020 Z=1
1030 GOTO 1060
1040 K=K+1
1050 IF K<=Q GOTO 1010
1060 RETURN
1070 END
1080 REM
1090 REM SUBROUTINE TO MULTIPLY ARRAY P BY 4
1100 REM
1110 C=0
1120 D=0
1130 FOR I=Q TO 0 STEP -1
1140 D=(P(I)*4+C) MOD 10
1150 C=(P(I)*4+C)\10
1160 P(I)=D
1170 NEXT I
1180 RETURN
1190 END